/*
 * @Author: 万仁杰
 * @Date: 2020-08-11 16:32:47
 * @LastEditTime: 2020-08-13 01:34:27
 * @LastEditors: 余文童
 * @Description: 商品控制器类
 * @FilePath: \BackEnd\saleflower\src\main\java\com\wangwang\saleflower\controller\FlowerController.java
 */
package com.wangwang.saleflower.controller;

import com.wangwang.saleflower.entity.ResultState;
import com.wangwang.saleflower.entity.ResultState.State;
import com.wangwang.saleflower.service.FlowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api")
public class FlowerController {

    @Autowired
    private FlowerService flowerService;

    @GetMapping(value = "/product/{id}")
    @ResponseBody
    public ResultState selectFlowerList(@PathVariable(name = "id") Integer id) {
        ResultState result;
        var flowerList = flowerService.selectFlowerByKind(id);
        if (flowerList.isEmpty()) {
            result = ResultState.CreateResult(State.ERROR, null, "该商品不存在");
        } else {
            result = ResultState.CreateResult(State.SUCCESS, flowerList, "成功查找");
        }
        return result;
    }
}
